<template>
    <div>
        
         <el-table :data="acticles" style="width: 100%">
            <el-table-column label="文章名称">
                <template slot-scope="scope">
                    {{scope.row.title}}
                </template>
            </el-table-column>
            <el-table-column label="发布人">
                <template slot-scope="scope">
                    {{scope.row.user.userName}}
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button @click="removeActicle(scope.row)" type="danger" icon="el-icon-delete" circle></el-button>
                </template>
            </el-table-column>
    </el-table>



    </div>
</template>

<script>
import axios from 'axios';
import { onMounted, ref } from '@vue/composition-api';
export default {
    setup(props, context) {
        axios.defaults.baseURL = 'http://localhost:3000';

        onMounted(() => {
            getActicles();
        })

        // 文章
        const acticles = ref([]);
        // 获取文章
        const getActicles = async function () {
            let { data: res } = await axios.get('/user/acticle/name/all');
            if (res.status != 200)
                return context.parent.$message.error('获取文章数据失败，请刷新重试');

            acticles.value = res.acticles;
        }


        // 删除文章
        const removeActicle = async function (item) {
            let { data: res } = await axios.delete(`/user/acticle/${item.title}`);
            if (res.status != 200)
                return context.parent.$message.error('删除文章失败，请刷新后重试');
            context.parent.$message.success('删除文章成功');
            getActicles();
        }

        const methods = { removeActicle }
        return {
            ...methods,
            acticles
        }
    }
}
</script>